import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import './tabs/tabs.dart';
import './router/router.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:provider/provider.dart';
import './provider/playAudioList.dart';
import './provider/audioProgress.dart';
import './provider/currentRoute.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import './android_back_desktop.dart';

import 'dart:io';
import 'package:flutter/services.dart';

void main() {
  runApp(MyApp());
  if (Platform.isAndroid) {
    // 设置状态栏背景及颜色
    SystemUiOverlayStyle systemUiOverlayStyle =
        SystemUiOverlayStyle(statusBarColor: Colors.transparent);
    SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    // SystemChrome.setEnabledSystemUIOverlays([]); //隐藏状态栏
  }
}

class MyApp extends StatefulWidget {
  MyApp({Key? key}) : super(key: key);

  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
      FlutterLocalNotificationsPlugin();

  @override
  void initState() {
    var _duration = Duration(seconds: 5);
    Timer(_duration, () async {
      // await _showNotification();
    });
    super.initState();
    var android = new AndroidInitializationSettings('@mipmap/ic_launcher');
    final InitializationSettings initializationSettings =
        InitializationSettings(android: android);
    flutterLocalNotificationsPlugin.initialize(
      initializationSettings,
    );
  }

  Future<void> _showNotification() async {
    const AndroidNotificationDetails androidPlatformChannelSpecifics =
        AndroidNotificationDetails(
            'your channel id', 'your channel name', 'your channel description',
            importance: Importance.max,
            priority: Priority.high,
            ticker: 'ticker');
    const NotificationDetails platformChannelSpecifics =
        NotificationDetails(android: androidPlatformChannelSpecifics);
    await flutterLocalNotificationsPlugin.show(
        0, '暂时不知道怎么用', '先放着吧', platformChannelSpecifics,
        payload: 'item x');
  }

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: Size(750, 1334),
      builder: () => MultiProvider(
        providers: [
          ChangeNotifierProvider(create: (_) => PlayAudioList()),
          ChangeNotifierProvider(create: (_) => AudioProgress()),
          ChangeNotifierProvider(create: (_) => atPlayRoute()),
        ],
        child: MaterialApp(
          title: "我的音乐",
          home: WillPopScope(
            onWillPop: () async {
              AndroidBackDesktop.backToDesktop();
              return false;
            },
            child: Tabs(),
          ),
          initialRoute: '/', //初始化的时候加载的路由
          onGenerateRoute: onGenerateRoute,
          builder: EasyLoading.init(),
        ),
      ),
    );
  }
}
